﻿using System;
using System.Collections.Generic;
using Dapper;
using zhangmenren.Db;
using zhangmenren.Models;

namespace zhangmenren.Repository
{
    public class ClassMSRepository:BaseRepository
    {
        public IEnumerable<ClassifyEntity> Select()
        {
            string sql = @"SELECT Id,Title,State,Ico FROM Classify";
            return Execute(connection => connection.Query<ClassifyEntity>(sql));  //Items = items.Skip((pageIndex - 1) * pageSize).Take(pageSize)
        }


        public int Add(ClassifyEntity entity)
        {
            string sql = @"INSERT INTO Classify 
                            (Title
                            ,Ico
                            ,State)
                        VALUES
                            (@Title
                            ,@Ico
                            ,@State)";
            return Execute(connection => connection.Execute(sql, entity));
        }

        public int Del(int id)
        {
            string sql = @"DELETE FROM Classify WHERE Id = @Id";
            return Execute(connection => connection.Execute(sql, new { Id = id }));
        }

        public int EditState(int id, bool state)
        {
            string sql = @"UPDATE Classify SET State = @State WHERE Id = @Id";
            return Execute(connection => connection.Execute(sql, new { Id = id, State = state }));
        }

    }
}
